package com.fyzk.activity.prize.item;

import android.graphics.Color;
import android.graphics.Typeface;
import android.text.Html;
import android.text.Spanned;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.activity.app.App;
import com.fyzk.data.AppLotteryInfos;
import com.fyzk.utils.AppUtil;
import com.fyzk.utils.LotteryIDUtils;
import com.tyjc.lottery.R;


public class DLTPrizeItem extends PrizeItemBase implements PrizeNumFormatInterface {

    @Override
    public String getLotteryName() {
        return AppLotteryInfos.getLotteryName(LotteryIDUtils.DLT_LOTTERY_ID_INT);
    }

    @Override
    public int getLogoResID() {
        return R.drawable.main_daletou;
    }

    @Override
    public Spanned formatPrizeNumSpanned(String str) {
        return Html.fromHtml(str);
    }

    @Override
    public Spanned formatPrizeNumSpanned() {
        String prizeNum = this.getPrizeNum();
        prizeNum = prizeNum.replace(",", "");
        prizeNum = prizeNum.replace("|", "");
        int arr_length = prizeNum.length() / 2;
        StringBuffer stb = new StringBuffer();
        for (int i = 0; i < arr_length; i++) {
            try {
                String num = prizeNum.substring(2 * i, 2 * i + 2);
                if (i < 5) {
                    stb.append("<font color=\"");
                    stb.append(PrizeItemBase.COLOR_RED);
                    stb.append("\">");
                    stb.append(num + "&nbsp");
                    stb.append("</font>");
                } else {
                    stb.append("<font color=\"");
                    stb.append(COLOR_BLUE);
                    stb.append("\">");
                    stb.append(num + "&nbsp");
                    stb.append("</font>");
                }
            } catch (Exception e) {
                stb.append("<font color=\"");
                stb.append("数据错误");
                stb.append("\">");
            }
        }
        return Html.fromHtml(stb.toString());

    }

    @Override
    public void initNumView(View view) {
        LinearLayout layout = (LinearLayout) view;
        layout.removeAllViews();
        String prizeNum = this.getPrizeNum();
        prizeNum = prizeNum.replace(",", "");
        prizeNum = prizeNum.replace("|", "");
        int arr_length = prizeNum.length() / 2;
        int width = AppUtil.dip2px(App.getContext(), 30);
        for (int i = 0; i < arr_length; i++) {
            String num = prizeNum.substring(2 * i, 2 * i + 2);
            TextView mTxt_ball = new TextView(App.getContext());
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, width);
            mTxt_ball.setGravity(Gravity.CENTER);
            mTxt_ball.setTextColor(Color.WHITE);
            mTxt_ball.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
            mTxt_ball.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));//加粗
            mTxt_ball.setText(num);
            if (i != 0) {
                layoutParams.setMargins(15, 0, 0, 0);
            }
            if (i < 5) {
                mTxt_ball.setBackgroundResource(R.drawable.dot_ball_red);
            } else {
                mTxt_ball.setBackgroundResource(R.drawable.dot_ball_blue);
            }
            mTxt_ball.setLayoutParams(layoutParams);

            layout.addView(mTxt_ball,layoutParams);
        }
    }

}
